package com.lesso.zgs.sunflower.controller;


import com.baomidou.mybatisplus.plugins.Page;
import com.lesso.zgs.sunflower.core.ApiResponse;
import com.lesso.zgs.sunflower.pojo.dto.EmployeeDTO;
import com.lesso.zgs.sunflower.pojo.dto.EmployeeQueryDTO;
import com.lesso.zgs.sunflower.pojo.vo.EmployeeVO;
import com.lesso.zgs.sunflower.service.IEmployeeService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;


/**
 * <p>
 * 员工基础信息 前端控制器
 * </p>
 *
 * @author zgs
 * @since 2025-07-02
 */
@RestController
@RequestMapping("/base/employee")
public class EmployeeController {
    @DubboReference
    private IEmployeeService employeeService;

    @PostMapping
    public ResponseEntity<Long> save(@RequestBody EmployeeDTO dto) {
        return ResponseEntity.ok(employeeService.save(dto));
    }

    @RequestMapping("/{id}")
    public ResponseEntity<EmployeeDTO> getById(@PathVariable Long id) {
        return ResponseEntity.ok(employeeService.getById(id));
    }


    @PutMapping
    public ResponseEntity<Integer> update(@RequestBody EmployeeDTO dto) {
        return ResponseEntity.ok(employeeService.update(dto));
    }

    @DeleteMapping("/{id}")
    public ResponseEntity<Integer> delete(@PathVariable Long id) {
        return ResponseEntity.ok(employeeService.delete(id));
    }


    @GetMapping("/page")
    public ApiResponse<com.baomidou.mybatisplus.plugins.Page<EmployeeVO>> page(EmployeeQueryDTO dto) {
        return ApiResponse.ok("success", employeeService.page(dto));
    }


    @GetMapping("/custom/page")
    public ApiResponse<Page<EmployeeVO>> customPage(EmployeeQueryDTO dto) {
        return ApiResponse.ok("success", employeeService.customPage(dto));
    }
}
